<include file="Common/common" />
<style type="text/css">
	.title{
		color: rgb(240,222,112);
		background: rgb(57,61,73)

	}
	.layui-tab-title .layui-this{
		color: rgb(240,222,112);
		background: #7d7d7d
	}
</style>
<body>
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this title">留言列表</li>
					<li class="title">留言反馈</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show" style="overflow-x: auto;">
						<table class="layui-table" id="feedback-list" style=" color: rgb(240,222,112);">
							<thead>
									<tr style="background: rgb(57,61,73)">
										<th>留言编号</th>
										<th>标题</th>
										<th>留言内容</th>
										<th>留言时间</th>
										<th>系统回复</th>
										<th>操作</th>
									</tr> 
								</thead>
								<tbody>
									<foreach name="feedbackList" item="vo">
										<tr  style="background: #7d7d7d;color:rgb(240,222,112);">
											<td>{$vo['id']}</td>
											<td>{$vo['title']}</td>
											<td>{$vo['content']}</td>
											<td><?php echo date('Y-m-d H:i:s',$vo['createtime']) ?></td>
											<td style="color: red;">{$vo['feedback']}</td>
											<td>
												<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" onclick="func_delete(this,{$vo['id']})" >删除</button>
											</td>
										</tr>
									</foreach>
								</tbody>
						</table>
						<div class="green-black">{$page}</div>
					</div>

					<div class="layui-tab-item">
						<form class="layui-form" id="feedback-form" action="">
							<div class="layui-form-item">
								<label class="layui-form-label" style=" color: rgb(240,222,112);" >用户名</label>
								<div class="layui-input-block">
									<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" autocomplete="off" value="{$userInfo['account']}" class="layui-input" disabled="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style=" color: rgb(240,222,112);">标题*</label>
								<div class="layui-input-block">
									<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="text" name="title" lay-verify="required|title" autocomplete="off" value="" class="layui-input" >
								</div>
							</div>
							
							<div class="layui-upload">
								<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="button" class="layui-btn" id="more-details">上传图片</button>
								<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;color:rgb(240,222,112)">
									图片
									<div class="layui-upload-list" id="demo3"></div>
								</blockquote>
								<div id="detail-arr-input">
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label" style=" color: rgb(240,222,112);">留言*</label>
								<div class="layui-input-block">
									<textarea style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" placeholder="" lay-verify="required" name="content" class="layui-textarea"></textarea>
								</div>
							</div>

							<input type="hidden" name="userId" value="{$userInfo['id']}">
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-feedback">立即提交</button>
									<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="reset" class="layui-btn">重置</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			
		</div>
	</div>
</body>

<script type="text/javascript">
	function func_delete(obj,id){
		layer.confirm('确定删除？',{offset:'none'},function(index){
			$.ajax({
		            type: "post",
		            url: "{:U('Feedback/ctrl_deleteFeedback')}",
		            data: {id:id},
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
		            		$(obj).parent().parent().remove();
		            	}
                        layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            }
			});
		});
	}

	layui.use(['upload','layedit'], function(){
		var form = layui.form,
		layer = layui.layer,
		layedit = layui.layedit;

		var $ = layui.jquery
		,upload = layui.upload;


		form.render();

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#upload-one-pic',
			url: "{:U('Common/UploadPic')}",
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#preview-pic').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res){
				
				if(res.code == 1){
					//上传成功
					document.getElementById("img_url").value = res.url;
                    return layer.msg('<span style="color: rgb(240,222,112);">上传成功</span>');
				}else{
					//如果上传失败
                    return layer.msg('<span style="color: rgb(240,222,112);">上传失败</span>');
				}
				
			},
			error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInst.upload();
				});
			}
		});


		//多详情图片上传
		upload.render({
			elem: '#more-details',
			url: "{:U('Common/UploadPic')}",
			multiple: true,
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
				$('#demo3').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
				});
			},
			done: function(res){
				//上传完毕
				if(res.code == 1){
					//上传成功
					var innerTD = '<input  name="imgurl_arr[]" value="'+res.url+'" type="hidden">';
					$(innerTD).appendTo('#detail-arr-input');
				}else{
					//如果上传失败
                    return layer.msg('<span style="color: rgb(240,222,112);">上传失败</span>');
				}
			}
		});


		//监听提交表单
		form.on('submit(btn-feedback)', function(data){
			layer.confirm('确定要提交？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('Feedback/ctrl_Feedback')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		               if (rtJson.code == 1) {
		              //  		var innerTD = '';
		              //  		innerTD+=
		              //  		"<tr>"+
		              //  			"<td>"+rtJson.data+"</td>"+
		              //  			"<td>"+data.field.title.trim()+"</td>"+
		              //  			"<td>"+data.field.content.trim()+"</td>"+
		              //  			"<td>"+rtJson.time+"</td>"+
		              //  			"<td></td>"+
		            		// "</tr>";
		            		// $(innerTD).prependTo('#feedback-list');
		            		// $('#feedback-form')[0].reset();//重置表单
                           layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		                    setTimeout(function(){location.reload();}, 1000);
					    }else{
                           layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
					    	
					    }
		            }
		        });
			});
			
	        return false;
		});

	});
</script>
<include file="Common/footer" />